package global

import (
	"github.com/sirupsen/logrus"
	"github.com/xuelang-group/suanpan-appconnector/pkg/common"
	"github.com/xuelang-group/suanpan-appconnector/pkg/pubsub"
	"github.com/xuelang-group/suanpan-appconnector/pkg/pubsub/redis"
)

var (
	Pubsub pubsub.PubSub
)

var (
	Version string = "UNKNOWN"
	Type    string = "UNKNOWN"
	Build   string = "UNKNOWN"
)

func PrintVersion() string {
	return common.PrintConnectGoVersion(Version, Type, Build)
}

func InitPubsub() {
	// init pubsub
	Pubsub = redis.NewRedisStreams()
	err := Pubsub.Init(pubsub.Metadata{
		Properties: map[string]string{
			"redisHost":   common.GetStreamRedisAddr(common.GetAppId()),
			"redisType":   "node",
			"consumerID":  "appconnector",
			"queueDepth":  "1000",
			"concurrency": "3",
		},
	})
	if err != nil {
		panic(err)
	}
	logrus.Info("pubsub init success.")
}
